package com.command.demo1.main;

import com.command.demo1.GarageDoor;
import com.command.demo1.Light;
import com.command.demo1.SimpleRemoteControl;
import com.command.demo1.impl.GarageDoorOpenCommand;
import com.command.demo1.impl.LightOnCommand;
import com.command.demo1.impl.NoCommand;

/**
 * 简单命令模式：将请求封装成对象，以便使用不同的请求、队列或者日志来参数化其他对象。命令模式也支持可撤销的操作
 * 
 * @author dell
 * 
 */
public class RemoteControlTest {

	public static void main(String[] args) {

		SimpleRemoteControl remote = new SimpleRemoteControl();
		Light light = new Light();
		GarageDoor garageDoor = new GarageDoor();
		LightOnCommand lightOn = new LightOnCommand(light);
		GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

		remote.setCommand(lightOn);
		remote.buttonWasPressed();
		remote.setCommand(garageOpen);
		remote.buttonWasPressed();

		// 这是一个空对象的例子，当你不想返回一个有意思的对象时，空对象就很有用了
		NoCommand noCommand = new NoCommand();
		remote.setCommand(noCommand);
		remote.buttonWasPressed();
	}

}
